import configparser
import threading
import os

class Config:
    #__new__()用于创建实例，而__init__()则负责初始化实例
    _instance_lock = threading.Lock()   #定义一把锁
    _flag = False   #类属性
    _configfile = r'D:/pycharm/test_selenium/web/config/config.ini'
    def __init__(self):
        if Config._flag:
            return

        config = configparser.ConfigParser()
        config.read(Config._configfile, encoding = 'UTF-8')
        self.__browserType = config.get('browserType','browserName')
        self.__targetUrl = config.get('targetUrl','url')
        self.__waitTime = config.get('waitTime', 'waitTime')
        self.__logFile = config.get('logFile', 'logFile')
        self.__reportPath = config.get('reportPath', 'reportPath')
        self.__elementFile = config.get('elementFile','elementFile')
        self.__dataPath = config.get('dataPath','dataPath')
        Config._flag = True

    def __new__(cls, *args, **kwargs):
        if not hasattr(cls, '_instance'):
            cls._instance_lock.acquire()
            if not hasattr(cls, '_instance'):
                cls._instance = super().__new__(cls)
            cls._instance_lock.release()
        return cls._instance

    @property
    def browerType(self):
        return self.__browserType
    @property
    def targetUrl(self):
        return self.__targetUrl
    @property
    def waitTime(self):
        return self.__waitTime
    @property
    def logFile(self):
        return self.__logFile
    @property
    def reportPath(self):
        return self.__reportPath

    @property
    def elementFile(self):
        return self.__elementFile

    @property
    def dataPath(self):
        return self.__dataPath